/*
 Copyright (C) 2009 QDSS.org
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.qdss.persist.engine;

import java.io.Serializable;
import java.sql.Connection;

import javax.sql.DataSource;


import org.qdss.persist.Entity;
import org.qdss.persist.dialect.Dialect;
import org.qdss.persist.metadata.MetadataFactory;
import org.springframework.jdbc.datasource.DataSourceUtils;

/**
 * 
 * 
 * @author <a href="mailto:zhaofang123@gmail.com">FANGFANG ZHAO</a>
 * @since 0.1.0, Mar 8, 2009
 * @version $Id: SQLExecutorContext.java 51 2009-05-06 07:45:48Z zhaofang123@gmail.com $
 */
public class SQLExecutorContext implements Serializable {
	private static final long serialVersionUID = 661188666290260734L;
	
	final private DataSource dataSource;
	final private MetadataFactory metadataFactory;
	final private Dialect dialect;

	public SQLExecutorContext(MetadataFactory metadataFactory, Dialect dialect,
			DataSource dataSource) {
		this.metadataFactory = metadataFactory;
		this.dialect = dialect;
		this.dataSource = dataSource;
	}

	public Dialect getDialect() {
		return dialect;
	}

	public Entity getEntity(String tname) {
		return metadataFactory.getEntity(tname);
	}

	public Entity getEntity(int tcode) {
		return metadataFactory.getEntity(tcode);
	}

	public Connection getConnection() {
		return DataSourceUtils.getConnection(getDataSource());
	}

	public DataSource getDataSource() {
		return dataSource;
	}
}
